package com.xyx.www;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;

public class Test0806 {
	public static void main(String[] args) {
		 fileReader();
		//fileBuffer();
	}

	private static void fileReader() {
		try {
			Reader fileRea = new InputStreamReader(
					new FileInputStream("D:\\JAVA\\LanqiaoWp\\test\\src\\com\\yuw\\oop\\lianxi\\Person.java"),
					"utf-8");
			Writer outRea = new OutputStreamWriter(
					new FileOutputStream("D:\\JAVA\\LanqiaoWp\\test\\src\\com\\yuw\\oop\\lianxi\\Person2.java", true),
					"utf-8");
			char[] cf = new char[1024];
			 int len=fileRea.read(cf);
			while(len>0) {
				outRea.write(cf, 0, len);
				len = fileRea.read(cf);
			}
			System.out.println("完成！！");
			outRea.flush();
			fileRea.close();
			outRea.close();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	private static void fileBuffer() {
		try {
			// 创建一个字符流输入对象
			//InputStreamReader 是字节流通向字符流的桥梁：它使用指定的 charset 读取字节并将其解码为字符。
			//它使用的字符集可以由名称指定或显式给定，或者可以接受平台默认的字符集。
			BufferedReader isr = new BufferedReader(new InputStreamReader(
					new FileInputStream("D:\\JAVA\\LanqiaoWp\\test\\src\\com\\yuw\\oop\\lianxi\\Manager.java"),
					"utf-8"));
			// 创建一个字符的输出流
			BufferedWriter osr = new BufferedWriter(new OutputStreamWriter(
					new FileOutputStream("D:\\JAVA\\LanqiaoWp\\test\\src\\com\\yuw\\oop\\lianxi\\Person2.java", false),
					"utf-8"));
			String strLine = isr.readLine();
			while (strLine != null) {
				osr.write(strLine);
				osr.newLine();
				strLine = isr.readLine();
			}
			System.out.println("写入完成！");
			// 清空输出流
			osr.flush();
			// 关闭资源
			osr.close();
			isr.close();

		} catch (Exception e) {
			// TODO: handle exception
		}
	}
}
